package two_pointer;

import linkedlist.ListNode;

/**
 * Created with IntelliJ IDEA.
 * Description: 206. 反转链表
 * User: Li_yizYa
 * Date: 2025/5/12
 * Time: 22:17
 */
public class Solution5 {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode pre = null;
        ListNode next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
}
